<!DOCTYPE htlm>
<html>
	<head>
		<meta charset="UTF-8" />
		<link rel="stylesheet" href="css/style.css" />
	</head>
	<body>

	<div class="popoutElement" id="pop-new-truc" style="display: none;">
	    <div class="content">
	    	<h1>Answer the question</h1>
	        <h2 id="question"></h2>
	        <input id="answer" type="text"/>
	        <a class="btn" onClick="otherTruc();">Other question</a>
	    </div>
	    <div class="lower">
			<a onClick="cancel();"><span data-icon="'" aria-hidden="true"></span>Cancel</a>
	        <a onClick="answer();"><span data-icon="/" aria-hidden="true"></span>Answer</a>
	    </div>
	</div>

	<div style="text-align:center;margin:30px 0 0">
		<!-- <h1 class="alarm_title"></h1>
		<p>groepswekker: <span></span></p> -->
		<div style="margin: 50px 0 0;">
			<button id="stopalarm" class="mooie-knop">
				Dismiss
			</button>
			<button id="snoozealarm" class="mooie-knop">
				Snooze
			</button>
		</div>
	</div>


	<script src="js/jquery-min.js"></script>
	<script src="js/cordova-2.0.0.js"></script>
	<script src="js/ajax.js"></script>
	<script src="js/imei.js"></script>
	<script src="js/wektruc.js"></script>
	<script>

		var data = window.wekker.getData();
			console.log(data);
			var id = data.split('/')[0];
			var days = data.split('/')[1];
			var groep = data.split('/')[2];
			var snoozetime = data.split('/')[3];
			console.log('wekker id = ' + id);
			console.log('days = ' + days);
			console.log('groep = ' + groep);
			console.log('snoozetime = ' + snoozetime);
			
		window.dismiss = false;

		

		$('h1.alarm_title').text('Wekker id = ' + id);
		//if(groep == 'true'){
		//	$('span').text('ja');
		//} else {
		//	$('span').text('nee');
		//}


		$('button#stopalarm').on('click', function(){
			
			if(!window.dismiss){
				getTruc();
				return;
			}

			if(groep == 'true'){
				console.log('ajax!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
				window.ajax.add({
					url : 'http://www.remcovdk.com/groupalarm/groupalarm.php',
					type : 'POST',
					data : {
						action : 'deactivate',
						idevent : id,
						set : 1,
						imei : window.imei
					},
					dataType : 'json',
				}, function(msg) {

				}, function(msg) {
					console.log('kan geen verbinding maken');
				});
			} else {
				if(days == 'no-repeat'){
					window.ajax.add({
						url : 'http://www.remcovdk.com/groupalarm/alarm.php',
						type : 'POST',
						data : {
							action : 'active',
							set : 0,
							idwekker : id,
							imei : window.imei
						},
						dataType : 'json',
					}, function(msg) {

					}, function(msg) {
						console.log('kan geen verbinding maken');
					});

				} else {
					var repDays = days.split(',');
				}
			}

			window.wekker.stopAlarm();

		});

		$('button#snoozealarm').on('click', function(){

			if(groep == 'true'){ // update status
				console.log('ajax!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
				window.ajax.add({
					url : 'http://www.remcovdk.com/groupalarm/groupalarm.php',
					type : 'POST',
					data : {
						action : 'deactivate',
						set : 2,
						idevent : id,
						imei : window.imei
					},
					dataType : 'json',
				}, function(msg) {
					console.log(msg);
				}, function(msg) {
					console.log('kan geen verbinding maken');
				});
			}

			var d = new Date();
			var hour = parseInt(d.getHours());
			var min = parseInt(d.getMinutes());

			console.log('hour' + hour);
			console.log('min' + min);

			var newhour = parseInt(hour);
			var newmin = min+parseInt(snoozetime);
			console.log('newmin' + newmin);
			if(newmin > 60){
				var newhour = hour+1;
				newmin-=60;
				console.log('newmin' + newmin);
				if(newhour > 24){
					newhour-=24;
				}
			}
			console.log('newhour' + newhour);
			console.log('newmin' + newmin);
			window.wekker.setAlarm(parseInt(id), newhour, newmin, groep, snoozetime);
			window.wekker.pauzeAlarm();

		});




	</script>

	</body>
</html>